% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% This code produces (part of) Table D
clear;
tic
addpath('..\..\Utilities')  
load actual_moments_k

weight=actual_moments_k(:,12);
sum(weight)
secteur=actual_moments_k(:,1);

load ..\..\Simulations_VC\MS_produits_KR_MC\stat4
param=stat4;

data=param(:,5:9)
meanw_data_all=weight'*param(:,5:9)/sum(weight);
for i=1:5
stdw_data(i)=sqrt(weight'*((param(:,i+4)-meanw_data_all(i)).^2)/sum(weight));
end

stdnw_data=std(param(:,5:9));
meannw_data_all=mean(param(:,5:9));

[stdnw_data./meannw_data_all; stdw_data./meanw_data_all]


%HE
meanw_data_he=weight(secteur ~=5)'*param((secteur ~=5),5:9)/sum(weight(secteur ~=5));
for i=1:5
stdw_data_he(i)=sqrt(weight(secteur ~=5)'*((param((secteur ~=5),i+4)-meanw_data_he(i)).^2)/sum(weight(secteur ~=5)));
end
stdnw_datahe=std(param((secteur ~=5),5:9));
meannw_data_he=mean(param((secteur ~=5),5:9));

[stdnw_datahe./meannw_data_he ; stdw_data_he./meanw_data_he]





load ..\..\Simulations_VC\Counterfactual_sim\MS_produits_KR_MC\stat_simu_out.mat


for jj=2:4
    
    data_sim=stat_simu_out(jj).stat_simu_out(:,6:10);
    size(data_sim)
    
for i=1:5
   % size(data_sim(:,i))
y=[data_sim(:,i) data(:,i)];
y=[data(:,i) data_sim(:,i)];

% r1 = corrcoef(y) 
% corr(i)=r1(2,1)% Traditional Correlation Matrix 
% r2 = weightedcorrs(y, weight) % Weighted Correlation Matrix
% corrw(i)=r2(2,1)% Traditional Correlation Matrix 

%p(i,:) = polyfit(y(:,1),y(:,2),1)
lm = fitlm(y(:,1),y(:,2))
p(i,:)=lm.Coefficients(2,1)
v(i,:)=lm.Coefficients(2,4)
y_he=[data((secteur ~=5),i) data_sim((secteur ~=5),i)];

% r1 = corrcoef(y_he) 
% corrhe(i)=r1(2,1)% Traditional Correlation Matrix 
% 
% r2 = weightedcorrs(y_he, weight((secteur ~=5))) % Weighted Correlation Matrix
% corrw_he(i)=r2(2,1)% Traditional Correlation Matrix 
%phe(i,:) = polyfit(y_he(:,1),y_he(:,2),1)
lm = fitlm(y_he(:,1),y_he(:,2))
phe(i,:)=lm.Coefficients(2,1)
vhe(i,:)=lm.Coefficients(2,4)
end
%corrt(jj,:)=corr;
%corrthe(jj,:)=corrhe;

%corrtw(jj,:)=corrw;
%corrthew(jj,:)=corrw_he;

p_tot(:,jj-1)=p(:,1)
phe_tot(:,jj-1)=phe(:,1)

v_tot(:,jj-1)=v(:,1)
vhe_tot(:,jj-1)=vhe(:,1)


end
